#include<stdio.h>
#include<string>
#include<iostream>
#include <algorithm>
using namespace std;
struct country
{
	string name;
	int pop1;//population
	int pop2;
	int del;
};
bool cmp(const country a, const country b)
{
	if (a.del == b.del)return a.name < b.name;
	if (a.del == 0)return false;
	if (b.del == 0)return true;
	return a.del > b.del;
}
int main()
{
	int n, i;
	struct country cou[1000], temp;
	//input
	scanf("%d", &n);
	for (i = 0; i < n; i++)cin >> cou[i].name;
	for (i = 0; i < n; i++)cin >> cou[i].pop1;
	for (i = 0; i < n; i++)cin >> cou[i].pop2;
	//rank
	for (i = 0; i < n; i++)cou[i].del = cou[i].pop2-cou[i].pop1;
	sort(cou, cou + n, cmp);
	//output
	for (i = 0; i < n; i++)cout << cou[i].pop2 - cou[i].pop1 << " " << cou[i].name <<endl;
	return 0;
}